package com.freeman.cement.config;

import com.freeman.cement.interceptor.TokenInterceptor;
import com.freeman.cement.util.SysConst;
import com.freeman.cement.util.file.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    TokenInterceptor tokenInterceptor;

    //registry是整个拦截器的注册中心
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                //允许通过的页面
                .excludePathPatterns("/login",
                        "/eventRecv",
                        "/eventRecvDebug",
                        "/eventRecvTest",
                        "/hikisc/**",
                        "/sysinfo/getInfo",
                        "/sysinfo/heart",
                        "/static/**",
                        SysConst.RESOURCE_PREFIX + "/**",
                        "/jsp/**",
                        "/phone/phoneCallback",
                        "/wsEvent/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //本地文件上传路径
//        registry.addResourceHandler("/static/PhoneDialogRecord/**").addResourceLocations("file:" + SysConst.PhoneDialogRecord_PATH + "/");
        registry.addResourceHandler("/static/PhoneDialogRecord/**").addResourceLocations("file:" + SysConst.PhoneDialogRecord_PATH + "/");
        registry.addResourceHandler("/static/EventPic/**").addResourceLocations("file:" + SysConst.EventPicBasePath + "/");
        registry.addResourceHandler("/static/**").addResourceLocations("file:" + SysConst.UPLOAD_FILE_PATH + "/");
        registry.addResourceHandler(SysConst.RESOURCE_PREFIX + "/**").addResourceLocations("file:" + FileUploadUtils.getDefaultBaseDir() + "/");
    }


}
